<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%@page import="java.util.List"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/layui.css"/>
		<style>
			tr{
				height: 50px;
			}
		</style>
		<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min-2.1.1.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/layui-v2.6.13/layui/layui.js"></script>
	</head>
	<body>
		<div style="padding: 20px; width: 90%; margin: 0 auto;">
			<form class="layui-form">
			<input type="hidden" name="id" value="${obj.id}">
				<table>
					<tr>
						<td>姓名：</td>
						<td><input type="text" class="layui-input" name="uName" value="${obj.uName}"></td>
						<td colspan="2">
						
							男<input type="radio" value="1" class="layui-input" name="sex" <c:if test="${obj.sex==1 }">checked=true</c:if> />
							女<input type="radio" value="0" class="layui-input" name="sex" <c:if test="${obj.sex==0 }">checked=true</c:if> />
						</td>
					</tr>
					<tr>
						<td>年级：</td>
						<td><input type="text" class="layui-input" name="sYear" value="${obj.sYear }"></td>
					</tr>
					<tr>
						<td>学院：</td>
						<td>
							<select name="collegeId" lay-filter="f1">
								<option value="">学院</option>
								<c:forEach items="${cs}" var ="clog">
									<option <c:if test="${obj.collegeId==clog.collegeId }">selected=true</c:if>
									value="${clog.collegeId }">${clog.sName }</option>
<%-- 									<option value="1">${clog.sName}</option> --%>
								</c:forEach>
							</select>
						<td>专业：</td>
						<td>
							<select name="majorId" id="major">
								<option value="${obj.majorId }">${obj.cName}</option>
							</select>
						</td>
					</tr>
					<tr>
						<td>班级：</td>
						<td><input type="text"  class="layui-input" name="classNo" value="${obj.classNo}"></td>
						<td>&nbsp;&nbsp;就业城市：</td>
						<td><input type="text" class="layui-input" name="city" value="${obj.city}"></td>
					</tr>
					<tr>
						<td>就业单位：</td>
						<td><input type="text" class="layui-input" name="company" value="${obj.company}"></td>
						<td>&nbsp;&nbsp;岗位：</td>
						<td><input type="text" class="layui-input" name="sPost" value="${obj.sPost}"></td>
					</tr>
					<tr>
						<td>薪资：</td>
						<td><input type="text" class="layui-input" name="wages" value="${obj.wages}"></td>
					</tr>
					<tr>
						<td>企业类型：</td>
						<td colspan="3">
							私企<input type="radio" value="1" class="layui-input" name="companyType">
							国企<input type="radio" value="2" class="layui-input" name="companyType">
							集体企业<input type="radio" value="3" class="layui-input" name="companyType">
							事业单位<input type="radio" value="4" class="layui-input" name="companyType">
							科研院所<input type="radio" value="5" class="layui-input" name="companyType">
						</td>
					</tr>
				</table>
			</form>
			<br>
			<button class="layui-btn layui-btn-fluid" onclick="insert();">更改</button>
		</div>
	</body>
	<script>
	layui.use(['layer','form'], function(){
		var layer = layui.layer;
		var form = layui.form;
	  
		form.on('select(f1)', function(data){
			console.info(data.elem); //得到select原始DOM对象
			console.info(data.value); //得到被选中的值
			
			var params = "m=listOfCollegeId&collegeId=" + data.value;
			$.ajax({
				url: "major",
				data: params,
				type: "POST",
				success: function(obj){
					//将json字符串转为数组
					var arr = JSON.parse(obj);
					
					//清空子元素
					$("#major").empty();
					//添加子元素
					$.each(arr,function(index, item){
						console.info(item);
						//在元素内部末尾插入子元素
						$("#major").append("<option value='"+item.collegeId+"'>"+item.cName+"</option>");
					});
					//重新渲染select下拉框
					form.render('select');
				}	
			});
		}); 
		});   
		//提交学生信息
		function insert(){
			var params = $("form").serialize();
			console.info(params);
			$.ajax({
				url: "s?m=stuInsert",
				data: params,
				type: "post",
				success: function(code){
					if(code == '1'){
						alert("更改成功");
					} else {
						alert("更改失败");
					}
					//延迟关闭
					setTimeout(closeLayer(), 500);
				}
			});
		}
		
		function closeLayer(){
			//关闭弹出层
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
			//刷新父页面
			window.parent.location.reload();
		}
	</script>
</html>